let test () =
  print_endline "Tototo"

let source = "let test () =
let toto () = () in

let sourceBuffer = GSourceView2.source_buffer ~highlight_syntax:true ()

let sourceview parent = GSourceView2.source_view 
  ~source_buffer:sourceBuffer
  ~auto_indent:true
  ~packing:parent#add ()"

let sourceBuffer = GSourceView2.source_buffer 
  ~text:source 
  ~highlight_syntax:true ()

let table = GText.tag_table ()

let get_color () = 
  let iterStart = sourceBuffer#get_iter_at_char ~line:1 0 in
  let iterEnd = sourceBuffer#get_iter_at_char ~line:1 11 in
  let retrievedText = sourceBuffer#get_text 
    ~start:iterStart 
    ~stop:iterEnd () in
  let sTag = sourceBuffer#create_tag ~name:"toto" [] in
  sTag#set_property (`BACKGROUND "red");
  sourceBuffer#apply_tag sTag iterStart iterEnd

let sourceview parent = GSourceView2.source_view 
  ~source_buffer:sourceBuffer
  ~auto_indent:true
  ~packing:parent#add ()

let color_debug infos color =
  Printf.printf "[%s] %s" color infos;
  print_endline ""

let parse_compilation_error infos = 
  let rexp_type = Str.regexp "Error: This expression has type .*" in
  let rexp_erro = Str.regexp "Error: .*" in
  let rexp_warn = Str.regexp "Warning: .*" in
  match infos with
    | "Error: Syntax error" -> color_debug "Syntax" "RED"; true
    | "Error: This function is applied to too many arguments;" 
      -> color_debug "Maybe you forgot a ';'" "RED"; true
    | _ as infos ->
      begin
        if (Str.string_match rexp_type infos 0) then
          begin
            color_debug ("Maybe you forgot a parameter"
                          ^"or use the wrong type\n"^infos) "RED";
            true
          end
        else if (Str.string_match rexp_erro infos 0) then
          begin
            color_debug infos "RED";
            true
          end
        else if (Str.string_match rexp_warn infos 0) then
          begin
            color_debug infos "YELLOW";
            true
          end
        else
          (
            color_debug "Build OK !" "GREEN";
            false
          )
      end 

let parse_compilation_line infos = 
  let rexp_line = Str.regexp ".* line \\([0-9]*\\), .*" in 
  let rexp_char = Str.regexp ".* characters \\([0-9]*\\)-\\([0-9]*\\):" in
  if (Str.string_match rexp_line infos 0) then
    begin
      print_endline (Str.replace_matched "\\1" infos);
      print_endline (Str.global_replace rexp_char "De \\1 a \\2" infos) 
    end
